-- card: 20223 from stack: in.3 -- bmap block id: 0 -- flags: 4000 -- background id: 16896 -- name: FindKey ----- HyperTalk script ----- on opencard global nextPos hide card field "source" set the scroll of card field "documentation" to 0 hide button "arrow" put 0 into nextPos set the loc of btn arrow to "312,40" pass opencard end opencard on Install get ChooseTargetStack() InstallResource XFCN,FindKey,it end Install -- part 3 (button) -- low flags: 00 -- high flags: A004 -- rect: left=337 top=236 right=271 bottom=456 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Find Reds ----- HyperTalk script ----- on mouseUp global nextPos get FindKey(card field demo,"red",4,false,nextPos) put it into found put item 2 of found into atLine if atLine is 0 then answer "No more found." put "312,40" into newLoc else put the textheight of card field demo into th get the rect of card field demo put item 2 of it into fTop put item 1 of the loc of btn "arrow" into newLoc put fTop+(atLine * th)-7 into item 2 of newLoc end if set the loc of btn arrow to newLoc show card btn arrow set the cursor to hand put item 1 of found + 1 into nextPos end mouseUp -- part 6 (button) -- low flags: 00 -- high flags: 8003 -- rect: left=304 top=299 right=321 bottom=425 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show C Source ----- HyperTalk script ----- on mouseUp get the visible of card field "source" set the visible of card field "source" to not it if it is false then set the name of me to "Hide C Source" else set the name of me to "Show C Source" end if end mouseUp -- part 8 (field) -- low flags: 01 -- high flags: 0004 -- rect: left=323 top=35 right=184 bottom=486 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 9 -- style flags: 0 -- line height: 12 -- part name: demo -- part 9 (field) -- low flags: 01 -- high flags: 2007 -- rect: left=18 top=33 right=287 bottom=295 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Documentation -- part 10 (button) -- low flags: 00 -- high flags: A004 -- rect: left=336 top=192 right=230 bottom=456 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Find Fords ----- HyperTalk script ----- on mouseUp global nextPos get FindKey(card field demo,"Ford",1,false,nextPos) put it into found put item 2 of found into atLine if atLine is 0 then answer "No more found." put "312,40" into newLoc else put the textheight of card field demo into th get the rect of card field demo put item 2 of it into fTop put item 1 of the loc of btn "arrow" into newLoc put fTop+(atLine * th)-7 into item 2 of newLoc end if set the loc of btn arrow to newLoc show card btn arrow set the cursor to hand put item 1 of found + 1 into nextPos end mouseUp -- part 11 (button) -- low flags: 00 -- high flags: 0000 -- rect: left=303 top=29 right=51 bottom=321 -- title width / last selected line: 0 -- icon id / first selected line: 16560 / 16560 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: arrow -- part 7 (field) -- low flags: 81 -- high flags: 0007 -- rect: left=18 top=31 right=290 bottom=489 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Source -- part contents for card part 7 ----- text ----- /* FindKey1.0.c */ /* © Trustees of Dartmouth College */ /* written in LightSpeed C © Think Technologies, Inc */ /* by Roger Brown 7/21/88 Courseware Development group */ /* From FindInField1.4.c */ /* This is a HyperCard XFCN that locates a target string in a specified item of an input field (or other container) and returns the byte position in the field, the number of the line where it was find, and the byte position in that line. Case sensitivity is used if an optional fourth parameter is "true". An optional fifth parameter can be sent to specify the byte position in the field where the search should start. Syntax is: get FindKey(container,target,items,"true",startByte) ex. get FindKey(card field 1,"***","3,4") returns: item 1: byte offset in field or 0 if not found item 2: line of card field 1 that contains '***' or 0 item 3: byte position in the line or 0 item 4: the item where it was found where container is any hypercard container (field, variable), presumed to be multi-lined. target is the string to look for items an item list of numbers that designate item positions to look in (defaults to 1) true is an optional parameter turning on case sensitivity startByte is an optional parameter specifying the byte position in the container where the search should start. To compile: create a project with this and MacTraps. Build as code resource type XFCN named FindKey. */ #include "stddata_ctype.c" #include "strings.c" #include "ToolboxUtil.h" #include "HyperXCmd.h" #include "XCmdGlue.inc.c" #include "SetUpA4.h" /* change a string to all upper case */ int toupper(c) char c; { return( (c>='a')&&(c<='z') ? (c-('a'-'A')) : c ); } /* see if two characters match, maybe ignoring case */ matchChar(a,b,theCase) char a,b; int theCase; { if (theCase==1) return (a==b); return (toupper(a)==toupper(b)); } /* build the return result string from numeric parts */ BuildResult(fPos,fLine,lPos,item,result) int fPos,fLine,lPos,item; char *result; { char temp[64]; NumToString((long)fPos,temp); PtoCstr((char*)temp); strcpy(result,temp); strcat(result,","); NumToString((long)fLine,temp); PtoCstr((char*)temp); strcat(result,temp); strcat(result,","); NumToString((long)lPos,temp); PtoCstr((char*)temp); strcat(result,temp); strcat(result,","); NumToString((long)item,temp); PtoCstr((char*)temp); strcat(result,temp); } ItemInList(item,items,numItems) int item; int items[32]; int numItems; { int i; for (i=0;i 32) numItems = 32; for (i=0;i start) { /* don't go until something matches */ while (matchChar(*tc,*fc,caseSens)) { /* check for match */ fc++; /* cycle through matching characters */ tc++; if ((tc == (theTarget+tLen))&& /* all target characters matched */ (ItemInList(item,itemList,numItems)==1)) { /* and its the right item */ BuildResult(c+1,line,lPos+1,item,result); return; /* matched */ } } } c++; /* move along */ lPos++; fc = theField + c; /* reset pointer after a search */ } BuildResult(0,0,0,0,result); return; /* target not found */ } /* XCMD entry */ pascal void FindKey(paramPtr) XCmdBlockPtr paramPtr; { int i; Str255 paramStr,theResult; Ptr theField,theTarget,theItems,casePtr,theStart; long line; Size len; CursHandle theCursor; Handle resultHandle; int theCase; long startAt; /* put up a watch */ theCursor = GetCursor(watchCursor); SetCursor(*theCursor); /* lock parameters down so we can point to them */ for (i=0;iparamCount;i++) { MoveHHi(paramPtr->params[i]); HLock(paramPtr->params[i]); } /* get the parameters */ theField = *(paramPtr->params[0]); /* the container */ theTarget = *(paramPtr->params[1]); /* the target string */ theItems = *(paramPtr->params[2]); /* the target item number */ if (paramPtr->paramCount>3) { /* case sensitivity flag */ casePtr = *(paramPtr->params[3]); strcpy(paramStr,casePtr); } else strcpy(paramStr,""); for (i=0;iparamCount>4) { /* start byte */ theStart = *(paramPtr->params[4]); strcpy(paramStr,theStart); CtoPstr((char *)paramStr); StringToNum(paramStr,&startAt); } else startAt = 0; /* do it */ FindIt(theField,theTarget,theItems,theCase,theResult,(int)startAt); /* assemble the return string */ len = 1+strlen(theResult); resultHandle = NewHandle(len); HLock(resultHandle); BlockMove(theResult,*resultHandle,len); HUnlock(resultHandle); paramPtr->returnValue = resultHandle; for (i=0;iparamCount;i++) HUnlock (paramPtr->params[i]); return; } pascal void main(paramPtr) XCmdBlockPtr paramPtr; /* this is the entry point for the XFCN */ { RememberA0(); SetUpA4(); /* to access globals */ FindKey(paramPtr); /* run the main event loop */ RestoreA4(); return; } -- part contents for card part 9 ----- text ----- FindKey version 1.0 Roger Brown This is a HyperCard XFCN that locates a target string in a specified item of an input field (or other container) and returns the byte position in the field, the number of the line where it was found, and the byte position in that line. Case sensitivity is used if an optional fourth parameter is "true". An optional fifth parameter can be sent to specify the byte position in the field where the search should start. INVOKING FindKey get FindKey (container,target,items,"true", startByte) where container is any HyperCard container (field, variable), presumed to be multi-lined. target is the string to look for items an item list of numbers that designate item positions to look in ( defaults to 1) true is an optional parameter turning on case sensitivity startByte is an optional parameter specifying the byte position in the container where the search should start. returns: item 1: byte offset in field or 0 if not found item 2: line of card field 1 that contains the target string or 0 item 3: byte position in the line or 0 item 4: the item where it was found EXAMPLE ex. get FindKey(card field 1,"***","3,4") This example will look in card field 1 for the first occurrence of the string *** in item 3 or item 4 of any line. REVISION HISTORY 1.0 First public release. -- part contents for card part 8 ----- text ----- Chevrolet, BelAir,1957,blue Ford,Thunderbird,1960,red Packard,Roadster,1939,black Kaiser,Jeep,1969,yellow Chevrolet, Impala,1967,red Ford,Fairlane,1970,white Plymouth,Reliant,1989,black Mercury,Cougar,1975,white VolksWagen, Beetle,1967,blue Ford,Mustang,1960,red Pontiac,GTO,1964,black Lincoln,Continental,1969,red